<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Input;
use DB;
use Session;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class LoginController extends Controller
{
   //登录的显示
    public function getLogin()
    {
        return view('login.login');
    }
    //注册的显示
    public function getRegister()
    {
        return view('login.register');
    }
    //注册的处理
    public function postCreate(){
        $input = Input::only('adminName','password','email');
        $input['password'] = md5($input['password']);
        $id = DB::table('admin')->insertGetId($input);
        if($id){
            Session::put('adminId', $id);
            return redirect('/admin');
        }else{
            return back()->with('error','注册失败');
        }
    }
    //登录的处理
    public function postLoginpro(){
        $input = Input::only('adminName', 'password');
        $input['password'] = md5($input['password']);
        $user = DB::table('admin')->where($input)->first();
        if($user){
            Session::put('adminId', $user->adminId);
            return redirect('/admin');
        }else{
            return back()->with('error','用户不在或者密码和账号错误');
        }
    }
    //退出登录
    public function getLogout(Request $request){
        $request->session()->forget('adminId');
        return redirect('/login/login');
    }
}
